using System;
using Microsoft.VisualStudio.Shell.Interop;

namespace VSSDKAssist.Assets.Helpers
{
	/// <summary>
	/// Class responsible for handling the VS Status Bar.
	/// </summary>
	public class StatusBarHelper
	{
		#region Fields
		IServiceProvider serviceProvider;
		#endregion

		#region Constructors
		/// <summary>
		/// Initializes a new instance of the <see cref="StatusBarHelper"/> class.
		/// </summary>
		/// <param name="serviceProvider">The service provider.</param>
		public StatusBarHelper(IServiceProvider serviceProvider)
		{
			this.serviceProvider = serviceProvider;
		}
		#endregion

		#region Properties
		private IVsStatusbar statusBar;

		/// <summary>
		/// Gets the status bar.
		/// </summary>
		/// <value>The status bar.</value>
		protected IVsStatusbar StatusBar
		{
			get
			{
				if(statusBar == null)
				{
					statusBar = (IVsStatusbar)serviceProvider.GetService(typeof(SVsStatusbar));
				}

				return statusBar;
			}
		}
		#endregion

		#region Public Implementation
		/// <summary>
		/// Displays the message.
		/// </summary>
		/// <param name="message">The message.</param>
		public void DisplayMessage(string message)
		{
			int frozen;

			StatusBar.IsFrozen(out frozen);

			if(frozen == 0)
			{
				StatusBar.SetText(message);
			}
		}

		/// <summary>
		/// Starts the animation.
		/// </summary>
		public void StartAnimation()
		{
			StartAnimation((short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_General);
		}

		/// <summary>
		/// Starts the animation.
		/// </summary>
		/// <param name="icon">The icon.</param>
		public void StartAnimation(short icon)
		{
			object dummy = icon;
			StatusBar.Animation(1, ref dummy);
		}

		/// <summary>
		/// Stops the animation.
		/// </summary>
		public void StopAnimation()
		{
			StopAnimation((short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_General);
		}

		/// <summary>
		/// Stops the animation.
		/// </summary>
		public void StopAnimation(short icon)
		{
			object dummy = icon;
			StatusBar.Animation(0, ref dummy);
		}
		#endregion
	}
}